<template>
  <div class="rules-list" v-bind:style="{ height:rulesListHeight + 'px' }">
    <div class="head clear-float" v-bind:style="{ height:headHeight + 'px' }">
      <el-form :model="formQuery" >
        <el-form-item label="bizType">
          <el-select v-model="formQuery.bizType" filterable placeholder="select please..." @change="bizTypeChange()">
            <el-option
              v-for="bizType in bizTypeList"
              :key="bizType.value"
              :label="bizType.label"
              :value="bizType.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="keyword">
          <el-input v-model="formQuery.keyword">
          </el-input>
        </el-form-item>
      </el-form>
    </div>
    <div class="body" v-bind:style="{ height:bodyHeight + 'px' }">
      <ul class="searchListUl fullHeightBody">
        <li v-for="rule in ruleHeadList" v-bind:class='{"actived":currentRuleId == rule.id}' @click="checkRule(rule, $event)">
          <span>{{rule.title}}</span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'RulesList',
    props: [],
    data () {
      return {
        "screenWidth": window.innerWidth,
        "screenHeight": window.innerHeight,
        "bizTypeList":[],
        "ruleHeadList":[],
        "currentRuleId":"",
        "formQuery":{
            "bizType":""
        },
        "headHeight":166,
        "bodyHeight":0,
        "rulesListHeight":0
      }
    },
    created: function() {
      var that = this;
      this.axios.get('/api/bizTypeList')
        .then(function (response) {
          that.bizTypeList = response.data.dataList;
        });
      window.onresize = () => {
        return (() => {
          window.screenWidth = window.innerWidth;
          that.screenWidth = window.screenWidth;
          window.screenHeight = window.innerHeight;
          that.screenHeight = window.screenHeight;
        })();
      }
    },
    updated: function() {
      var that = this;
      //fullHeight操作
      that.fullHeight();
    },
    methods: {
      fullHeight: function() {
        var _winHeight = window.innerHeight;
        var _elm = this.$vnode.elm;
        //容器到底
        this.rulesListHeight = _winHeight - _elm.parentElement.parentElement.offsetTop;
        //内容部分做出适应性的操作
        this.bodyHeight = this.rulesListHeight - this.headHeight;
      },
      bizTypeChange: function() {
        var that = this;
        that.axios.get('/api/ruleHeadListBybizType', {
          params: {
            "bizType":that.formQuery.bizType
          }
        })
        .then(function (response) {
          that.ruleHeadList = response.data.dataList;
        });
      },
      //规则点击
      checkRule: function(tar, event) {
        var that = this;
        that.axios.get('/api/ruleList', {
          params: {
            "cRHeadId":tar.id
          }
        })
        .then(function(response) {
          var data = {
            "title": tar.title,
            "dataList": response.data.dataList,
            "ynFlag":tar.ynFlag
          }
          that.currentRuleId = tar.id;
          that.$emit('dataChange', data);
        });
      }
    },
    watch: {
      "screenWidth": function(val) {
        this.fullHeight();
      },
      "screenHeight": function(val) {
        this.fullHeight();
      }
    }
  }
</script>
